<div class="layui-row layui-col-space15">
	<div class="layui-col-md12">
		<div class="layui-card hxr-layui-card">
			<div class="layui-form hxradmin-card-header">
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">学校名称</label>
						<div class="layui-input-inline">
							<input type="text" name="users" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-inline">
						<button class="layui-btn" data-type="reload" id="searchs">搜索</button>
					</div>
				</div>
			</div>
			<div class="layui-card-body">
				<table class="layui-hide" id="list-select-table" lay-filter="list-select-table"></table>
			</div>
		</div>
	</div>
</div>
<div class="form-btn" style="bottom: -20px;">
	<input type="button" value="确认选择" class="layui-btn selectok">
 </div>
<script>
	//表格数据渲染
	layui.use(['table', 'form'], function() {
		var table = layui.table,
			form = layui.form,
			$ = layui.$;

			layui.admin.initlist(table,'schools/list',350,[
				[{
					type: 'radio'
				}, {
					field: 'schools_id',
					title: 'ID',
					width: 60
				}, {
					field: 'school_name',
					title: '学校名称',
					minWidth: 150
				}, {
					field: 'create_time',
					title: '创建时间',
					width: 200
				}]
			],'#list-select-table',380,{obj:layui.admin.schools,val1:'schools_id',val2:'school_id'})
		//搜索
		$('#searchs').on('click', function() {

			var val1 = $('input[name="users"]').val()
			//执行重载
			table.reload('list-select-table', {
				page: {
					curr: 1 //重新从第 1 页开始
				},
				where: {
					search_text: val1
				}
			});
		});
		$('.selectok').click(function(){
			var checkStatus = table.checkStatus('list-select-table')
			,checkData = checkStatus.data[0];
			if(!checkData){
				layer.msg('请选择负责学校');
			}else{
				if(layui.admin.schools.school_id!=checkData.schools_id){

					if (layui.admin.schools.school_ids.indexOf(checkData.schools_id)!=-1){

						layer.msg('这个学校已经选过了，不要重复选');
						return false;
					}
					layui.admin.schools.institute_name='';
				}
				layui.admin.schools.school_id=checkData.schools_id;
				layui.admin.schools.school_name=checkData.school_name;
				layer.close(layui.admin.pups);
			}
		});
	});
</script>
